//
//  BaseViewController.m
//  Feast
//
//  Created by 胡光健 on 2017/8/23.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = HJColorRGB(248);
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }

}


- (void)setNavTitle:(NSString *)navTitle {
    _navTitle = navTitle;
    self.navigationItem.title = navTitle;
}

- (void)setLeftNavTitle:(NSString *)leftNavTitle {
    _leftNavTitle = leftNavTitle;
    if (self.leftNavImageName.length) {
        [self configLeftButton];
        return;
    }
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:leftNavTitle style:UIBarButtonItemStylePlain target:self action:@selector(didClickLeftNavAction)];
}

- (void)setRightNavTitle:(NSString *)rightNavTitle {
    _rightNavTitle = rightNavTitle;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:rightNavTitle style:UIBarButtonItemStylePlain target:self action:@selector(didClickRightNavAction)];
}

- (void)setRightNavImageName:(NSString *)rightNavImageName {
    _rightNavImageName = rightNavImageName;
    UIImage *image = [[UIImage imageNamed:rightNavImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(didClickRightNavAction)];
}

- (void)setLeftNavImageName:(NSString *)leftNavImageName {
    _leftNavImageName = leftNavImageName;
    if (self.leftNavTitle.length) {
        [self configLeftButton];
        return;
    }
    UIImage *image = [UIImage imageNamed:leftNavImageName];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(didClickLeftNavAction)];
}
- (void)configLeftButton {
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 60, 30);
    leftBtn.titleLabel.font = HJFontSize(16);
    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    leftBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    [leftBtn setTitle:self.leftNavTitle forState:0];
    [leftBtn setTitle:self.leftNavTitle forState:UIControlStateHighlighted];
    [leftBtn setImage:[UIImage imageNamed:self.leftNavImageName] forState:0];
    [leftBtn setImage:[UIImage imageNamed:self.leftNavImageName] forState:UIControlStateHighlighted];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    [leftBtn addTarget:self action:@selector(didClickLeftNavAction) forControlEvents:UIControlEventTouchUpInside];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
- (void)didClickLeftNavAction {
    
}

- (void)didClickRightNavAction {
    
}
- (void)dealloc {
    [mNotificationCenter removeObserver:self];
}
@end
